package application.view
{
	import application.ApplicationFacade;
	import application.view.components.PostForm;
	
	import flash.events.Event;
	
	import org.puremvc.interfaces.IMediator;
	import org.puremvc.interfaces.INotification;
	import org.puremvc.patterns.mediator.Mediator;
	
	public class PostFormMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "PostFormMediator";
		
		public function PostFormMediator( viewComponent:Object )
		{
			super( viewComponent );
			
			postForm.addEventListener( PostForm.SUBMIT, onSubmit );
		}
		
		override public function getMediatorName():String
		{
			return NAME;
		}
		
		override public function listNotificationInterests():Array
		{
			return new Array( ApplicationFacade.MODEL_CHANGED );
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch ( notification.getName() )
			{				
				case ApplicationFacade.MODEL_CHANGED:
					postForm.clear();
					break;
			}
		}
		
		protected function get postForm():PostForm
		{
			return viewComponent as PostForm;
		}
		
		private function onSubmit(event:Event):void
		{
			sendNotification( ApplicationFacade.SUBMIT_POST, postForm.post );
		}
	}
}